import 'package:flutter/material.dart';
import 'package:flutter_swiper_null_safety/flutter_swiper_null_safety.dart';
import 'package:haokezufang/widgets/common_image.dart';

const List<String> defaultImages = [
  "https://www.wanandroid.com/blogimgs/42da12d8-de56-4439-b40c-eab66c227a4b.png",
  "https://www.wanandroid.com/blogimgs/62c1bd68-b5f3-4a3c-a649-7ca8c7dfabe6.png",
  "https://www.wanandroid.com/blogimgs/50c115c2-cf6c-4802-aa7b-a4334de444cd.png"
];
var imageWidth = 750.0;
var imageHeight = 424.0;

/// 轮播
class CommonSwipper extends StatelessWidget {
  final List<String> images;

  const CommonSwipper({super.key, this.images = defaultImages});

  @override
  Widget build(BuildContext context) {
    //屏幕宽度
    var height = MediaQuery.of(context).size.width / imageWidth * imageHeight;
    return SizedBox(
        height: height,
        child: Swiper(
          autoplay: true,
          containerHeight: height,
          itemBuilder: (BuildContext context, int index) {
            return CommonImage(
              src: images[index],
              width: double.infinity,
              height: height,
              fit: BoxFit.fill,
            );
          },
          itemCount: images.length,
          pagination: const SwiperPagination(),
          // control: SwiperControl(),
        ));
  }
}
